package com.slipper.system.organization.front;

import com.slipper.common.bo.Result;
import com.slipper.common.util.ResultUtil;
import com.slipper.system.api.organization.bo.OrganizationBO;
import com.slipper.system.api.organization.service.IOrganizationSv;
import com.slipper.system.organization.service.OrganizationService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrganizationSv implements IOrganizationSv {
    @Resource
    private OrganizationService organizationService;

    @Override
    public Result<OrganizationBO> queryBy(String id){
        return ResultUtil.successResult(organizationService.queryBy(id));
    }

    @Override
    public Result<List<OrganizationBO>> queryList(OrganizationBO bo) {
        return ResultUtil.successResult(organizationService.queryList(bo));
    }

    @Override
    public Result<List<OrganizationBO>> queryPage(OrganizationBO bo){
        return ResultUtil.successResult(organizationService.queryPage(bo));
    }

    @Override
    public Result<?> save(OrganizationBO bo) {
        try {
            return ResultUtil.saveResult(organizationService.save(bo), bo);
        } catch (Exception e) {
            return ResultUtil.failureResult(e.getMessage());
        }
    }

    @Override
    public Result<?> delete(OrganizationBO bo){
        return ResultUtil.deleteResult(organizationService.delete(bo));
    }

    @Override
    public Result<OrganizationBO> queryUnitOrg(String id) {
        return ResultUtil.successResult(organizationService.queryUnitOrg(id));
    }

    @Override
    public Result<OrganizationBO> queryByName(OrganizationBO bo) {
        return ResultUtil.successResult(organizationService.queryByName(bo));
    }

    @Override
    public Result<?> saves(List<OrganizationBO> list) {
        organizationService.saves(list);
        return ResultUtil.successResult("导入成功！");
    }

    @Override
    public Result<?> updateValid(OrganizationBO bo) {
        return ResultUtil.operateResult(organizationService.updateValid(bo), "设置");
    }
}
